//
//  PersistManager.m
//  PetTown
//
//  Created by lanou3g on 15/6/6.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "PersistManager.h"

@implementation PersistManager

static PersistManager * manager = nil;

+ (PersistManager *)shareInstance
{
    if (manager == nil) {
        
        manager = [[PersistManager alloc] init];
        
    }
    
    return manager;
}
#pragma  mark------数据库操作
//将对象归档
- (NSData *)dataOfArchiverObject:(id)object forKey:(NSString *)key
{
    NSMutableData * data = [NSMutableData data];
    
    NSKeyedArchiver * archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver encodeObject:object forKey:key];
    [archiver finishEncoding];
    
    
    return data;
}

//反归档
- (id)unarchiverObject:(NSData *)data forKey:(NSString *)key
{
    NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
    
    id object = [unarchiver decodeObjectForKey:key];
    [unarchiver finishDecoding];
    
    
    return object;
}
//收藏成功
- (UIAlertController *)collect{
    UIAlertController * collectAlert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功!" preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:nil];
    [collectAlert addAction:action];
    return collectAlert;
}
//重复收藏
- (UIAlertController *)repetitionCollect{
    UIAlertController * collectAlert = [UIAlertController alertControllerWithTitle:@"提示" message:@"该页面已经收藏!" preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:nil];
    [collectAlert addAction:action];
    return collectAlert;
}

@end
